package com.lz.androidlibraries.activity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.work.Constraints;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;

import com.liuyk.commonlib.activity.BaseSwipeRefreshWithLoadingActivity;
import com.lz.androidlibraries.R;
import com.lz.androidlibraries.cor.Coroutine;
import com.lz.androidlibraries.work.UploadLogWorker;

/**
 * DESC
 * <p>
 * Created by liuyakui on 2020/5/31.
 */
public class TestActivity extends BaseSwipeRefreshWithLoadingActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setLoadingContent(R.layout.activity_test);
        showContentView();
        setLeftIcon(R.mipmap.back_black);
        setTopBarTitle("用来测试");
        init();
        new Coroutine().main();
    }

    private void init() {
        findViewById(R.id.work_manager).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                start(getActivity());
            }
        });
    }

    public void start(Context context) {
        Constraints constraints = new Constraints.Builder()
                .build();
        OneTimeWorkRequest uploadWorkRequest = new OneTimeWorkRequest.Builder(UploadLogWorker.class)
                .setConstraints(constraints)//设置触发条件
                .build();

        WorkManager.getInstance(context).enqueue(uploadWorkRequest);
    }

    @Override
    protected void onRetry() {

    }

    @Override
    protected boolean isShowToolBar() {
        return true;
    }
}
